home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / x / gui / xfract.lha / xfract / xlmntn.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-27  |  2.8 KB  |  113 lines

  1. /*****************************************************************************
  2. /* FILE        : xlmntn.c
  3. /* AUTHOR    : Paul Sharpe @ DEC (OSCR-Europe, Reading, England).
  4. /* DATE        : July 20, 1989
  5. /* FUNCTION    : X-windows Fractal Brownian-Motion mountains.
  6. /* INSPIRATION    : 'The Science Of Fractal Images.'
  7. /*
  8. /*   Copyright (c) Digital Equipment Corporation 1990  All rights reserved.
  9. /*   Copyright is claimed in the computer program and user interface thereof.
  10. /*
  11. /*   Digital Equipment Corporation cannot accept any responsibility for
  12. /*   use, misuse, or abuse of this software.
  13. /*
  14. /*****************************************************************************/
  15.  
  16. #include <stdio.h>
  17. #include <math.h>
  18.  
  19. #include <X11/Xlib.h>
  20. #include <X11/Xatom.h>
  21. #include <X11/Xutil.h>
  22.  
  23. #include "xpt.h"
  24. #include "xlmntn.h"
  25.  
  26. main(argc,argv)
  27. int    argc;
  28. char    *argv[];
  29. {
  30.     xpt_getargs(args,NUMARGS,argc,argv);
  31.     init();
  32.     gen_mntndata(mntndata.elevs,square, (double)(square-5));
  33.     elevs2coords();
  34.     process_events();            /* Main event-processing loop. */
  35. }
  36.  
  37. init()
  38. {
  39.     init_cmn();
  40.     obsheight = atoi(ARGS(13));
  41.     if ((mntndist = atoi(ARGS(13))) < 1)
  42.     mntndist = 200;
  43.     if ((scrndist = atoi(ARGS(14))) < 1)
  44.     scrndist = 2000;
  45.     screenwidth = square*scrndist/mntndist;
  46.     screenheight= screenwidth;
  47.     zeroy = screenheight - obsheight*scrndist/mntndist;
  48.     init_X();
  49. }
  50.  
  51. elevs2coords()
  52. {
  53. register int    x,y;
  54.  
  55.     basey = square;
  56.     DEBUG(("Converting elevations to Y-coordinates...\n"));
  57.  
  58.     for (y=0; y<square; y++) {
  59.     for (x=0; x<square; x++) {
  60.         if (mntndata.elevs[x][y] <= 0.0)
  61.         mntndata.elevs[x][y] = 0.000000;
  62.         mntndata.px[x][y] = PIXELX(x,y);
  63.         mntndata.py[x][y] = PIXELY(x,y,(int)floor(mntndata.elevs[x][y]));
  64.     }
  65.     }
  66. }
  67.  
  68. display()
  69. {
  70.     draw_grid();
  71.     draw_heights();
  72. }
  73.  
  74. draw_grid()
  75. {
  76. XPoint    pnts[4];
  77.  
  78. /* Colour the main grid ('the sea') polygon. */
  79.     PNTS(0, PIXELX(0,0),       PIXELY(0,0,0));
  80.     PNTS(1, PIXELX(square,0),       PIXELY(square,0,0));
  81.     PNTS(2, PIXELX(square,square), PIXELY(square,square,0));
  82.     PNTS(3, PIXELX(0,square),       PIXELY(0,square,0));
  83.     XFillPolygon(dsply,wndw,seagc,pnts,4,Nonconvex,CoordModeOrigin);
  84. }
  85.  
  86. draw_heights()
  87. {
  88. register int    x,y;
  89. XPoint        pnts[5];
  90.  
  91.     for (y=square-1; y>=0; y--) {
  92.     for (x=0; x<square; x++) {
  93.         if (y < square-1 && x > 0) {
  94.         if (mntndata.elevs[x][y] > 0   || mntndata.elevs[x-1][y] > 0 ||
  95.             mntndata.elevs[x][y+1] > 0 || mntndata.elevs[x-1][y+1] >0) {
  96.  
  97.             PNTS(0, mntndata.px[x][y],     mntndata.py[x][y]);
  98.             PNTS(1, mntndata.px[x-1][y],   mntndata.py[x-1][y]);
  99.             PNTS(2, mntndata.px[x-1][y+1], mntndata.py[x-1][y+1]);
  100.             PNTS(3, mntndata.px[x][y+1]  , mntndata.py[x][y+1]);
  101.             draw_face(pnts, mc);
  102.  
  103.             if (y == 0) {
  104.             PNTS(2, mntndata.px[x-1][y], PIXELY(x-1,y,0));
  105.             PNTS(3, mntndata.px[x][y]  , PIXELY(x  ,y,0));
  106.             draw_face(pnts, -1);
  107.             }
  108.         } /* if elevs... */
  109.         } /* if y */
  110.     }
  111.     }
  112. }
  113.